package com.demo.money.controller.costdetails;

import com.demo.money.model.Costdetails;
import com.demo.money.service.CostdetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * CostdetailsAddNoKeyHtml类<br>
 * costdetails/AddNoKey.html页面里的请求映射关系
 * <p>
 * <b>常用方法</b>：<br>
 * 1.addNoKeyInsert - 添加消费信息，单条
 * <p>
 * <b>全类名</b>:com.demo.money.controller<br>
 * <b>类名</b>:CostdetailsAddNoKeyHtml<br>
 * <b>创建者</b>:张峰浦<br>
 * <b>创建时间</b>:2020/3/16 20:09<br>
 */
@Controller
public class CostdetailsAddNoKeyHtml {
    @Autowired
    private CostdetailsService costdetailsService;

    /**
     * 添加消费信息，单条
     *
     * @param userId              所属id
     * @param valid               有效？
     * @param amountofmoney       应付金额
     * @param amountofmoneyactual 实付金额
     * @param largeclass          分类
     * @param subclass            消费性质
     * @param tradename           消费名称
     * @param satisfactiondegree  满意度
     * @param note                备注
     * @param time                支付时间
     * @return 响应页面
     */
    @RequestMapping({"addNoKeyInsert", "addNoKeyInsert.html"})
    public String addNoKeyInsert(@RequestParam("userId") Integer userId, @RequestParam("valid") Integer valid, @RequestParam("amountofmoney") Float amountofmoney, @RequestParam("amountofmoneyactual") Float amountofmoneyactual, @RequestParam("largeclass") String largeclass, @RequestParam("subclass") String subclass, @RequestParam("tradename") String tradename, @RequestParam("satisfactiondegree") String satisfactiondegree, @RequestParam("note") String note, @RequestParam("time") String time) {

        costdetailsService.insert(new Costdetails(null, userId, valid, amountofmoneyactual, amountofmoney, largeclass, subclass, tradename, satisfactiondegree, note, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(time, new ParsePosition(0)), new Date()));

        return "costdetails/indexList";

    }

}
